package com.seeyon.apps.kk.util;

import com.seeyon.apps.kk.constants.Constants;
import com.seeyon.client.CTPRestClient;
import com.seeyon.client.CTPServiceClientManager;
import com.seeyon.ctp.common.SystemEnvironment;

public class RestUtil {
	
	/** 验证服务对象 */
    private static RestUtil restUtil = null;

    // 定义REST动态客户机
    private static CTPRestClient client = null;

    /**
     * 单例对象,私有化构造函数
     */
    private RestUtil() {
    }

    /**
     * 获取实体对象
     * @return
     */
    public static RestUtil getInstence() {
        if(restUtil == null) {
        	restUtil = new RestUtil();
        	CTPServiceClientManager clientManager
 			= CTPServiceClientManager.getInstance(SystemEnvironment.getInternetSiteURL());
		 	// 取得REST动态客户机。
        	client = clientManager.getRestClient();
        }
        return restUtil;
    }
    
    public String getToken() {
		return client.get("token/"+Constants.restName+"/"+Constants.restPwd, String.class,"text/plain");
	}

    /**
     * 验证权限
     * @return 验证结果
     */
    public boolean authenticate() {
        return client.authenticate(Constants.restName, Constants.restPwd);
    }

    /**
     * 获取client
     * @return client
     */
    public CTPRestClient getClient() {
        return client;
    }

    /**
     * 设置client
     * @param client client
     */
    public void setClient(CTPRestClient client) {
        this.client = client;
    }
}
